package com.tianhui.consignortwofei.pattern.orderOprate.impl;

import android.content.Context;

import androidx.annotation.NonNull;

import com.fgs.common.widget.dialog.OperateTipDialog;
import com.tianhui.consignortwofei.manager.EventBusManage;
import com.tianhui.consignortwofei.mvp.model.enty.OrderOperateInfo;
import com.tianhui.consignortwofei.pattern.orderOprate.IOrderOperate;
import com.tianhui.consignortwofei.pattern.orderOprate.OrderOperateCallback;
import com.tianhui.consignortwofei.pattern.orderOprate.OrderRequestOperate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fgs
 * @date 2020/8/29
 * @description 单据撤销
 **/
public class RevocationOperate implements IOrderOperate {
    @Override
    public void orderOperate(Context context, OrderOperateInfo operateInfo) {

        new OperateTipDialog.Builder(context)
                .title("提示")
                .content("是否撤销订单？")
                .positiveText("确定")
                .onPositive(new OperateTipDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull OperateTipDialog dialog) {
                        dialog.dismiss();
                        Map<String, String> map = new HashMap<>();
                        map.put("billno", operateInfo.orderInfo.billno);
                        map.put("isstate", "0");
                        new OrderRequestOperate().orderOperateRequest(context, map, operateInfo.orderInfo.dingJinType,
                                new OrderOperateCallback() {
                            @Override
                            public void operateCallback() {
                                showRevocationResultDialog(context);
                                EventBusManage.refreshOrderList();

                            }

                            @Override
                            public void onFailed(String message) {
                                showRevocationResultDialog(context, message);
                            }
                        });
                    }
                })
                .negativeText("取消")
                .show();


    }

    private void showRevocationResultDialog(Context context) {
        showRevocationResultDialog(context, "订单撤销成功");
    }

    private void showRevocationResultDialog(Context context, String message) {
        new OperateTipDialog.Builder(context)
                .title("提示")
                .content(message)
                .positiveText("确定")
                .isCancelable(false)
                .onPositive(new OperateTipDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull OperateTipDialog dialog) {
                        EventBusManage.activityFinish();
                        EventBusManage.operateActivityFinish();
                    }
                })
                .show();
    }

//    @Override
//    public void orderOperate(Context context, OrderOperateInfo operateInfo, OrderOperateCallback orderOperateCallback) {
//        Map<String, String> map = new HashMap<>();
//        map.put("billno", operateInfo.orderInfo.billno);
//        map.put("isstate", "0");
//        new OrderRequestOperate().orderOperateRequest(context, map, orderOperateCallback);
//    }
}
